package giab.weixin.web.httpservice;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.springframework.stereotype.Component;


@Component 
public class WeixinHttpBaseService {
	
	public static String LOGIN_URL = "http://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";
	public static String INDEX_URL = "http://mp.weixin.qq.com/cgi-bin/indexpage?t=wxm-index&lang=zh_CN";
	public static String FANS_URL = "http://mp.weixin.qq.com/cgi-bin/contactmanagepage?t=wxm-friend&lang=zh_CN&pagesize=10&pageidx=0&type=0&groupid=0";
	public static String SEND_MSG = "http://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response&lang=zh_CN";
	
	
	
	
	/**
	* @author 张怡菲
	* @createTime 	2013-5-9 下午4:00:58
	* @Title: postUrlResultCookies
	* @Description: TODO(这里用一句话描述这个方法的作用)
	* @param url
	* @param postParam
	* @return    String
	* @modifyTime	2013-5-9 下午4:00:58
	* @modifyNote (在这里说明修改了什么)
	* 
	*/
	
	public Map<String, String> postUrlResultCookies(HashMap<String, String> postParam) {
		 Map<String, String> cookies = null;
		try {
			Response response = Jsoup.connect(LOGIN_URL).ignoreContentType(true).method(Method.POST).data(postParam).execute();
			cookies = response.cookies();
			response = Jsoup.connect(INDEX_URL).ignoreContentType(true).method(Method.POST).cookies(cookies).execute();
			cookies = response.cookies();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return cookies;
	}

	

}
